# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '.\assets\progress.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets, Qt


# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '.\assets\progress.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QProgressBar, QHBoxLayout, QVBoxLayout, QLabel
# from ui_py.progress import Ui_Form
import time

class ProgressBar(QtWidgets.QWidget):
    def __init__(self):
        super(ProgressBar, self).__init__()
        self.progressBar = QProgressBar(self)
        self.progressBar.setMinimum(0)
        self.progressBar.setMaximum(100)
        self.progressBar.setProperty("value", 0)
        self.progressBar.setStyleSheet("QProgressBar {\n"
        "    border-style:solid;\n"
        "    border-color: grey;\n"
        "    border-radius: 7px;\n"
        "    border-width: 2px;\n"
        "    text-align: center;\n"
        "}\n"
        "QProgressBar::chunk {\n"
        "    width: 2px;\n"
        "    margin: 4px;\n"
        "    background-color: #6CFF80;\n"
        "}")
        self.h_layout = QHBoxLayout()
        self.v_layout = QVBoxLayout()
        self.label = QLabel(self)
        self.label.setText("")
        self.v_layout.addWidget(self.progressBar)
        self.v_layout.addWidget(self.label)
        self.setLayout(self.v_layout)
        self.resize(400, 50)
    def setValue(self, begin, val):
        while begin < val:
            begin += 1
            time.sleep(0.1)
            self.progressBar.setProperty("value", begin)
        # self.progressBar.setProperty("value", val)
    def setValue2(self, begin, val):
        while begin < val:
            begin += 2
            time.sleep(0.01)
            self.progressBar.setProperty("value", begin)
    def clear(self):
        self.progressBar.setProperty("value", 0)


class WorkThread(Qt.QThread):
    threadSignal = Qt.pyqtSignal(int)

    def __init__(self):
        super().__init__()

    def run(self, *args, **kwargs):
        c = 0
        while True:
            Qt.QThread.msleep(1000)
            c += 1
            self.threadSignal.emit(c)
        return Qt.QThread.run(self, *args, **kwargs)
